﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine.EventSystems;
[RequireComponent(typeof(ScrollRect))]
public class PackageOptimize : MonoBehaviour,IBeginDragHandler,IDragHandler
{
    public Transform SpecicalOBJ;

    // 总共有多少行 或者列
    public int AllRow = 15;
    // 每一行或者列有多少个
    public int RowNum = 4;
    /// <summary>
    /// 向上、左滑动  或者 是 向右、下 滑动
    /// </summary>
    private bool UpLeftOrRightDown = false;
    
    //Item模版
    public Transform TemplateTran;

    public ScrollRect ScrollRectOfPackage;
    // 怎么判断当前的ScrollView 是在向上移动还是在向下移动

    // Use this for initialization
    void Start ()
    {
        if (this.ScrollRectOfPackage == null)
        {
            this.ScrollRectOfPackage = this.transform.GetComponent<ScrollRect>();
        }
        Debug.Log(this.ScrollRectOfPackage.verticalNormalizedPosition);
        this.ScrollRectOfPackage.onValueChanged.AddListener
            ( (v2) => {

                //Debug.Log(this.ScrollRectOfPackage.verticalNormalizedPosition);
                this.TestSpceicalOBJPosInRecttransform();
            });
        //this.ScrollRectOfPackage.OnBeginDrag();
	}

    [ContextMenu("TestSpceicalOBJPosInRecttransform")]
    public void TestSpceicalOBJPosInRecttransform()
    {
        if (this.SpecicalOBJ == null)
        {
            return;
        }
        Debug.LogError("sizedata " +  this.ScrollRectOfPackage.viewport.sizeDelta);
        var pos = this.ScrollRectOfPackage.viewport.InverseTransformPoint(this.SpecicalOBJ.transform.position);
        var pos1 = this.ScrollRectOfPackage.content.InverseTransformPoint(this.SpecicalOBJ.transform.position);
        Debug.LogError("this.spcial pos " +  pos  + "this.content pos1 " + pos1);
    }

    private void OnLeftOrUpSilde()
    {

    }
    private void OnLeftOrDwon()
    {

    }

    private void OnScrollBeginDrag()
    {

    }
    private void OnScrollDragEnd()
    {

    }
    private void OnScrollDraging()
    {

    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        this.ScrollRectOfPackage.OnBeginDrag(eventData);
        Debug.LogError("this is begin drag");
    }

    public void OnDrag(PointerEventData eventData)
    {
        this.ScrollRectOfPackage.OnDrag(eventData);
        Debug.LogError("this is  drag");

    }
}
